//
//  City.m
//  Utils
//
//  Created by enghou on 2018/4/21.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "City.h"

@implementation City
-(instancetype)initWithSource:(NSDictionary *)source{
    self = [super initWithSource:source];
    if (self) {
        self.code = [self contentForKey:@"val" withSource:source];
        NSMutableArray *cs = [NSMutableArray array];
        [source.allKeys enumerateObjectsUsingBlock:^(NSString *key, NSUInteger idx, BOOL * _Nonnull stop) {
            if (![key isEqualToString:@"val"]) {
                self.name = key;
                NSDictionary *city = [source objectForKey:key];
                NSDictionary *countrys = [city objectForKey:@"items"];
                for (NSString *key in countrys.allKeys) {
                    Country *c = [[Country alloc]init];
                    c.name = key;
                    c.code = [countrys objectForKey:key];
                    [cs addObject:c];
                }
            }
        }];
        self.countrys = cs;
    }
    return self;
}
@end
